import { onMounted, reactive } from "vue";
import {useToast} from 'vue-toast-notification';

export default function() {
    const car = reactive(
        {
            band: "bmw",
            model: "x5",
            year: 2020,
            price: 50000
        }
    )
    
    function changePrice() {
    
        if (car.price > 40000)
            car.price -= 1000;
        else if (car.price === 40000)
            $toast.open({
                type:"warning",
                message:"cannt decrease！",
                position:"top"
            })
    
    }

    const $toast = useToast()

    onMounted(()=>{
        setTimeout(() => {
            $toast.open({
                type:"success",
                message:"welcome to car shop!",
                position:"top"
            })
        }, 10);
    })

    return {
        car,
        changePrice
    }
}